<?php
    if ($_COOKIE['LOG'] == false) {
        header('Location: ../index.php');
    }
    include_once '../config.php';
?>
<!DOCTYPE html>
<html>
    <head>
        <title>WeZett v1.0</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <style type="text/css" media="screen">@import "../jqtouch/jqtouch.css";</style>
        <style type="text/css" media="screen">@import "../theme/theme.css";</style>
        <script src="../jqtouch/jquery-1.4.2.js" type="text/javascript" charset="utf-8"></script>
        <script src="../jqtouch/jqtouch.js" type="application/x-javascript" charset="utf-8"></script>
        <script type="text/javascript" charset="utf-8">
            var jQT = new $.jQTouch({
                icon: 'wzicon.png',
                icon4: 'wzicon.png',
                addGlossToIcon: false,
                startupScreen: 'start.png',
                statusBar: 'grey',
                preloadImages: [
                    'theme/img/activeButton.png',
                    'theme/img/back_button.png',
                    'theme/img/back_button_clicked.png',
                    'theme/img/blueButton.png',
                    'theme/img/button.png',
                    'theme/img/button_clicked.png',
                    'theme/img/grayButton.png',
                    'theme/img/greenButton.png',
                    'theme/img/redButton.png',
                    'theme/img/whiteButton.png',
                    'theme/img/loading.gif'
                    ]
            });
            
            function new_client() {
                if(document.getElementById('new_client_check').checked){
                    document.getElementById('p_client').style.display = "none";
                    document.getElementById('client_name').style.display = "";
                    document.getElementById('client_street').style.display = "";
                    document.getElementById('client_zip').style.display = "";
                    document.getElementById('client_city').style.display = "";
                } else {
                    document.getElementById('p_client').style.display = "";
                    document.getElementById('client_name').style.display = "none";
                    document.getElementById('client_street').style.display = "none";
                    document.getElementById('client_zip').style.display = "none";
                    document.getElementById('client_city').style.display = "none";    
                }
            }
            
        </script>
        <style type="text/css" media="screen">
            #jqt.fullscreen #home .info {
                display: none;
            }
            div#jqt #about {
                padding: 100px 10px 40px;
                text-shadow: rgba(255, 255, 255, 0.3) 0px -1px 0;
                font-size: 13px;
                text-align: center;
            }
            div#jqt #about p {
                margin-bottom: 8px;
            }
            div#jqt #about a {
                color: #fff;
                font-weight: bold;
                text-decoration: none;
            }
        </style>
    </head>
    <body>
        <div id="jqt">
            <div id="add" class="current">
                <div class="toolbar">
                    <h1>Hinzufügen</h1>
                    <a class="cancel flipright" href="javascript:window.location = 'index.php'">Abbrechen</a>
                </div>
                <div class="info">
                    Felder die mit einem * gekennzeichnet sind, sind Pflichtfelder
                </div>
                <form id="p_add" action="work/p_add.php" method="POST" class="form">
                    <br />
                    <h2>Projekt-Nr.: 
                    <?php
                        $sql = "SELECT * FROM project WHERE year = '" . date('Y') . "' AND month = '" . date('m') . "' ORDER BY ym_p_nr DESC LIMIT 1";
                        $result = mysql_query($sql);
                        
                        if (mysql_num_rows($result) > 0) {
                            $data = mysql_fetch_array($result);
                            $project_nr_single = $data['ym_p_nr'] + 1;
                            if ($project_nr_single < 10) {
                                $project_nr_single = "0" . $project_nr_single;
                            }
                            $project_nr = date('Y-m'). '-' . $project_nr_single;
                            echo 'A ' . $project_nr;
                        } else {
                            $project_nr = date('Y-m'). '-01';
                            echo 'A ' . $project_nr;
                        }
                    ?>
                    </h2>
                    <ul class="rounded">
                        <li><input type="text" id="p_name" name="p_name" placeholder="Projektname *" /></li>
                    </ul>
                    <h2>Anschrift</h2>
                    <ul class="rounded">
                        <li><input type="text" id="p_street" name="p_street" placeholder="Straße / Haus-Nr." /></li>
                        <li><input type="tel" id="p_zip" name="p_zip" placeholder="Postleitzahl" /></li>
                        <li><input type="text" id="p_city" name="p_city" placeholder="Ort *" /></li>
                    </ul>
                    <h2>Auftraggeber</h2>
                    <ul class="rounded">
                        <li>Neu Anlegen: <span class="toggle"><input type="checkbox" id="new_client_check" name="ncc" onchange="new_client()"/></span></li>
                    </ul>
                    <?php
                        $sql = "SELECT * FROM client";
                        $result = mysql_query($sql);
                    ?>
                    <ul class="rounded" id="new_client">
                        <li id="p_client">
                            <select name="p_client">
                        <?php
                            if (mysql_num_rows($result) > 0) {
                                while ($data = mysql_fetch_array($result)) {
                        ?>
                            <option value="<?php echo $data["client_id"]; ?>"><?php echo $data["name"]; ?></option>        
                        <?php
                                }
                            } else {
                        ?>
                                <option>Keine Auftraggeber vorhanden</option>
                        <?php
                            }
                        ?>
                            </select>
                        </li>
                        <li id="client_name"style="display:none" ><input type="text" name="client_name" placeholder="Auftraggeber *" /></li>
                        <li id="client_street" style="display:none" ><input type="text" name="client_street" placeholder="Straße / Haus-Nr. *" /></li>
                        <li id="client_zip" style="display:none" ><input type="tel" name="client_zip" placeholder="Postleitzahl *" /></li>
                        <li id="client_city" style="display:none" ><input type="text" name="client_city" placeholder="Ort *" /></li>
                    </ul>
                    <h2>Datum der Anfrage</h2>
                    <ul class="rounded">
                        <li><input type="date" id="p_date" name="p_date" /></li>
                    </ul>
                    <a href="#" style="margin: 10px;" class="greenButton submit">Projekt hinzufügen</a>
                </form>
            </div>
        </div>
    </body>
</html>
